# _*_ coding : utf-8 _*_
# @Time : 2023/3/15 0015 22:47
# @Author : 菜鸟王小二
# @File : 17_xpath使用
# @Project : python爬虫

from lxml import etree
# etree.parse()解析本地文件
tree = etree.parse('xpath.html')
# 查看有id属性的
# li_list = tree.xpath('//ul/li[@id]/text()')
# print(li_list)

# li_list = tree.xpath('//ul/li[@id="l1"]/text()')
# print(li_list)

# li_list = tree.xpath('//ul/li[@id="l1"]/@class')
# print(li_list)

# li_list = tree.xpath('//ul/li[@class="c2"]/text()')
# print(li_list)

li_list = tree.xpath('//ul/li[contains(@id,"d")]/text()')
print(li_list)

# li_list = tree.xpath('//ul//li[@id="l2" and @class="c2"]/text()')
# print(li_list)

# li_list = tree.xpath('//ul/li[@id="l1"]/text() | //ul/li[@class="f1"]/text()')
# print(li_list)